package com.cn.elite.nj;

import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class test {
	private static String url = "http://192.168.2.80:8080/FlexClient/flex/EliteClient.html?debug=true&staffId=SELITE&projectId=gzl111&rolegroupId=SYSTEM&password=123";
	private static Integer error = 0;
	private static Integer threads = 200;
	private static Long startTime;
	public static void main(String[] args) throws IOException {
		InputStream  inStream  =  new  FileInputStream("c:\\aa.txt");
        byte[] aa=InputStreamToByte(inStream);
        for(int i=0;i<aa.length;i++){
     	   System.out.println(i+":"+aa[i]); 
        }
        
	}
	private static byte[] InputStreamToByte(InputStream is) throws IOException {  
		   ByteArrayOutputStream bytestream = new ByteArrayOutputStream();  
		   int ch;  
		   while ((ch = is.read()) != -1) {  
		    bytestream.write(ch);  
		   }  
		   byte imgdata[] = bytestream.toByteArray();  
		   bytestream.close();  
		   return imgdata;  
		  }
	private static class WorkThread extends Thread {
		public void run(){
			long start = System.currentTimeMillis();
			long end = 0;
			while(true){
				try {
					URL u = new URL(url);
					HttpURLConnection  urlConn = (HttpURLConnection)u.openConnection();
					urlConn.setUseCaches(false);
					urlConn.setRequestProperty("Content-type", "text/html; charset=UTF-8");
					urlConn.setRequestMethod("POST");
//					urlConn.setRequestProperty("Proxy-Connection", "Keep-Alive");
//					urlConn.connect();
//					//System.out.printf( "小博士页面编码: %s\n", urlConn.getContentEncoding());
//					InputStream is = urlConn.getInputStream();
//					StringBuffer buffer = new StringBuffer();
//					readToBuffer(buffer, is);
					urlConn.setDoOutput(true);
					urlConn.getOutputStream();
					end = System.currentTimeMillis();
					Thread.sleep(100);
				} catch (Exception e) {
					synchronized(error){
						error ++;
						System.out.printf("连接失败：%d\n", error);
					}
					e.printStackTrace();
				}
				
			}
		}

		public void readToBuffer(StringBuffer buffer, InputStream is)
				throws IOException {
			String line; // 用来保存每行读取的内容
			BufferedReader reader = new BufferedReader(
					new InputStreamReader(is));
			line = reader.readLine(); // 读取第一行
			while (line != null) { // 如果 line 为空说明读完了
				buffer.append(line); // 将读到的内容添加到 buffer 中
				buffer.append("\n"); // 添加换行符
				line = reader.readLine(); // 读取下一行
			}
		}
	}
}

